In this video we learn how to use some more advanced filtering techniques service to the mess that's
uh between IS and the to the operator.
So first of all let's import pandas and we are working with our Olympic Games medal status said
And now let's assume that we want to have all medals from these Summer Games in nineteen hundred eighty
eight and so and we can filter our data frame by checking in the column if the value for each row in
the year columnist 1988
and by doing so you'll be creating a really serious and bypassing the boolean serious here to the Logue
operator.
We are creating a brand new data frame with the only rows them that fulfill the condition here.
So let's try it out and star the new data frame and the variable Olympic Games nineteen eighty eight.
And let's check head and tail
so you can see here that we only have medals that were awarded in the year nineteen eighty eight and
so let's check also the info method.
So we have in total one thousand five hundred forty six medals.
And now what if you want to have not only the medals for one year but for example all medals since 1992
so from the addition in 1992 in Barcelona including until today.
And what we could actually do is we could create a boolean serious for each additional so let's say
we create a boolean serious for 1992 then a boolean serious for 1996 with the equals sign and so on
and then we could combine all boolean series with an R operator or what we could do we could simply
use that the Creator equals sign and that we are filtering all rows that the year is 1992 or later so
we don't have to use your many conditions and combine them with an operator we can just use here the
greater or equal sign and let's do this and save the new data frame and the variable Olympic Games since
the 1992
and let's have a look at the first and last throws.
So here we can see we have a data frame starting from 1992 until 2012.
So the dataset ends here in 2012 and the 2016 edition.
So now that a frame.
All right.
So now let's assume that you want to have all medals that were awarded in the 1960s.
So we want to include all games in the 1960s and we can do this.
So the between mass it so we can first of all select the year column and then use that between method
and check if the values in the year series between 1960 and 1969.
So let's check this here.
So we get here a boolean serious and obviously here for the very first rows we get a false because some
of that data frame is starting with eighteen hundred ninety six.
And now again we can pass here our boolean serious to our complete data frame with the local operator
and with the.
Between method that is one additional parameter here.
So this the between method we have to define the left boundary it's 1960 and the right boundary it's
1969 and we have to define if the boundaries are inclusive or exclusive.
So since we want to f all editions in the 60s we pass here through and here we are creating a brand
new data frame and we are storing the data frame and the variable Olympic Games.
60s so let's run the cell and let's have a look at the first rose and the last rose and you can see
here we are starting with the rose where the years are 1960.
So we have here the addition in Rome and we are ending with the 1968 in Mexico.
So and this is actually the good thing with the between method that this works even if I'm not sure
and which yes some Olympic Games took place.
So I do not have to pass a specific year where I know that there was Olympic Summer Games.
So for example in 1964 I simply pass an interval.
So between 1960 and 1969 and I get here the medals for the additions 1960 1964 and 1968.
All right so so far we selected editions that were on a sequential order.
So for example here we selected all games from 1992 until today.
Here we selected all games between 1960 and 1968.
But but if you want to select the Olympic Games that are not sequentially ordered so let's assume that
our favorite games were the additions in 1972 and 1996.
So they are obviously not sequential because they are games between those two for example in nineteen
seventy six or 1992 and
that's create here a list of my favorite games so in 1972 and 1996
and now if you want to filter the data frame we could use two conditions so we feel that for 1972 and
for nineteen ninety six and we combine those two conditions with an R operator all we could use the
s in method so we select first of all the column and then we use in the S1 method and then we pass our
list my favorite games with the two values 1972 and 1996 and then pan as checks for each value in the
year column if the value is either 1972 or 1996.
So let's run near the set and I would expect to get a brilliant serious correct.
And now we can pass here our brilliant series to our summer data frame and the load operator and then
we create a brand new data frame was the medals that were awarded in 1972 or 1996 and we call the data
frame Olympic Games 70 to 96 so let's run here and let's have a look at the first five rows.
And the last five rows so we are starting here with 1972 and ending with the 1996 and let's assume that
we deeply analyze here our data frame and now we want to analyze all other years that are not 1972 or
1996 and we can do this by passing simply here again now append us seriously with all rows with the
1972 on 1996 and then we can use the 2 December which gives us the opposite and then we can pass here
the whole statement to our summer data frame and the log operator and we should get a brand new data
frame with all matters in all year except the additions 1972 and 1996 and we saw the new data frame
and the venerable Olympic summer games not seventy two in 1960.
So let's check this out here.
Let's have a look.
So starting from hundred nineteen six and we can check give us the unique method which uh unique value
is we actually have in our year column so let's check this and we can see that we have all yes except
the years 1972 and 1996.
So our code worked here.
All right so now we are finished with this session and I hope to see you on the next one by.